﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WxSDK.BLL
{
    public class Wx_Menu : Base<WxSDK.Model.wx_menu>
    {
         public bool MarkMenu(int memberId)
         {
             List<WxSDK.Model.wx_menu> wx_menu = new List<WxSDK.Model.wx_menu>();
             string where = string.Format(" MemberId={0} and ParentId=0 ", memberId);
             string order = " SortId asc ";
             List<WxSDK.Model.wx_menu> wx_menu_parent = Query(10, where, order).ToList<WxSDK.Model.wx_menu>(); //拿到父菜单

             for (int i = 0; i < wx_menu_parent.Count(); i++)
             {
                 wx_menu.Add(wx_menu_parent[i]);
                 List<WxSDK.Model.wx_menu> wx_menu_child = Query(20, string.Format(" MemberId={0} and ParentId={1} ", memberId, wx_menu_parent[i].Id), " SortId asc ").ToList<WxSDK.Model.wx_menu>();
                 for (int j = 0; j < wx_menu_child.Count; j++)
                 {
                     wx_menu.Add(wx_menu_child[j]);
                 }
             }
             WeChatMsg wxmsg = new WeChatMsg();
             string json = "";//wxmsg.MenuJson(wx_menu);
             
             return wxmsg.PostDataToWeChat(string.Format(WeChat_Url.CreateMenu,  WeChatApi.GetAccessToken(memberId)), json);

         }
    }
}
